<template>
  <!-- form section start -->
  <section class="w3l-workinghny-form bg-white">
    <!-- /form -->
    <div class="workinghny-form-grid">
      <div class="wrapper">
        <div class="workinghny-block-grid">
          <div class="workinghny-left-img align-end">
            <img src="/statiLog/images/2.png" class="img-responsive" alt="img"/>
          </div>
          <div class="form-right-inf">

            <div class="login-form-content">
              <h2>Where to?</h2>
              <form class="signin-form" method="post">
                <div class="one-frm">

                  <label>User</label>
                  <input v-model="username" type="text" @keyup.enter="login">
                </div>
                <div class="one-frm">
                  <label>Password</label>
                  <input v-model="pwd" type="password" @keyup.enter="login">
                </div>
                <label class="check-remaind">
                  <input type="checkbox" v-model="remember">
                  <span class="checkmark"></span>
                  <p class="remember">Remember Me</p>

                </label>
                <p @click="login()" class="btn btn-style mt-3 text-center">Sign In</p>
              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- //form -->
    <!-- copyright-->

    <!-- //copyright-->
  </section>
  <!-- //form section start -->
</template>

<script>
import axios from 'axios'
import $store from "../store/index";

import {computed, onMounted} from "vue";

export default {
  name: "login",
  setup() {
    function setLoged(param) {
      $store.dispatch('setLog', param);
    }

    let loged = computed(() => {
      return $store.state.loged
    });
    return {
      setLoged,
      loged
    }
  },
  created() {
    this.setLoged(false)
  },
  data() {
    return {
      username: '',
      pwd: '',
      remember: true
    }
  },
  methods: {
    keydown(e) {
      console.log(e.keyCode)
    },
    login: function () {
      console.log(this.remember)
      axios.post("/api/open/TeacherLogin", {
        "UserName": this.username,
        "Password": this.pwd
      }).then((res) => {
        if (res.status === 200) {
          window.localStorage.setItem("zjxClass_teacherinfo", JSON.stringify(res.data))
          this.$store.commit('setLoged', true)
          this.$router.push({path: "/"})
          this.setLoged(true)
        } else {
          console.log("dw")

        }
      })
    },
  }
}
</script>

<style scoped>

</style>